using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PlayerLoop;

public class Fist:MeleeWeapon {
	public Fist(WeaponData stat) : base(stat) { }

	int attackIndex;
	const int attackCount = 3;

	protected override void PreProcess(ShotStats shot) {
		if(slot.inAfterAttack)
			attackIndex=(attackIndex+1)%attackCount;
		base.PreProcess(shot);
	}

	public override Projectile ShootSingleProjectile(Vector2 position,Angle direction,ProjectileData projectile,Dictionary<int,int> consumedAmmo) {
		bool doUpperCut = attackIndex==attackCount-1;
		return base.ShootSingleProjectile(
			position,
			doUpperCut ? (state.faceRight ? direction+(Angle)40 : direction-(Angle)40) : direction,
			projectile,
			consumedAmmo
		);
	}

	protected override void ProjectileFiringEventHandler(object _sender,ProjectileEventArgs e) {
		base.ProjectileFiringEventHandler(_sender,e);
		if(!IfReactFireEvent(_sender,e)) return;

		if(attackIndex==attackCount-1) {
			e.stat.size.AddMultiply(1.5f,-100);
			e.stat.damage.AddMultiply(2f,-100);
			e.stat.timeTotal.AddMultiply(1.5f,-100);
			e.stat.knockback.AddAdd(1,0);
		}
	}

	public override void Update() {
		base.Update();
		if(!slot.inAfterAttack&&!slot.inAttack)
			attackIndex=0;

		slot.SetAttackIndex(attackIndex);
	}

}
